//4305不重复的数
/*
#include <iostream>
#include <set>
using namespace std;

const int maxsize = 100000;

int main() {
    int m; cin >> m;
    for (int i = 0; i < m; i ++) {
        int n; cin >> n;
        set<int> alist; //使用set的问题就是，set会自动排序而非按照原顺序存储
        for (int j = 0; j < n; j ++) {
            int a; cin >> a;
            alist.insert(a);
        } //这里使用本地处理

        bool first = true;
        for (auto it = alist.begin(); it != alist.end(); ++it) { 
            if (!first) {
                cout << " ";
            }
            cout << *it;
            first = false;
        }
        cout << endl;
    }
    return 0;
}
*/

#include<bits/stdc++.h>
#define int long long
using namespace std;
struct num{
    int id;
    int z;
}s[50024];
int read(){
    int w=1,q=0;
    char ch=' ';
    while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
    if(ch=='-')w=-1,ch=getchar();
    while(ch>='0'&&ch<='9')q=q*10+ch-'0',ch=getchar();
    return w*q;
}
bool cmz(struct num a,struct num b){
    if(a.z>b.z)
        return true;
    if(a.z==b.z)
        if(a.id<b.id)
            return true;
    return false;
}
bool cmid(struct num a,struct num b){
    if(a.id<b.id)
        return true;
    return false;
}
signed main(void){
    int t,n,pd;
    t = read();
    while(t--){
        scanf("%lld",&n);
        for(int i=1;i<=n;i++){
            s[i].id = i;
            s[i].z = read();
        }
        sort(s+1,s+n+1,cmz);
        for(int i=1;i<=n;i+=pd){
            pd = 1;
            for(int j=i+1;j<=n;j++){
                if(s[i].z==s[j].z)s[j].z = -2147483659,pd++;
                else break;
            }
        }
        sort(s+1,s+n+1,cmid);
        for(int i=1;i<=n;i++){
            if(s[i].z!=-2147483659)printf("%lld ",s[i].z);
        }
        printf("\n");
    }
    return 0;
}
